/**
 * COPYRIGHT HangZhou Trustway Technology Company Limited
 * All right reserved.
 */
package com.zfsmart.component.common.util;

import java.util.Date;
import java.util.Random;

/**
 * @Description
 * @Author 薛铁琪
 * @CreateTime 2020-07-26 17:06
 * @Version 1.0
 */
public class UuidUtil {


    public static String createUuid(String prefix) {
        StringBuffer stringBuffer = new StringBuffer();
        String parse = DateUtil.formatDate(new Date(), DateUtil.fullDatePattern);
        String randomString = String.format("%06d", new Random().nextInt(9999999));
        String orderNo = stringBuffer.append(prefix).append(parse).append(randomString).toString();
        return orderNo;
    }

    /**
     * @param min
     * @param max
     * @return Random number
     */

    public static int getRandomIntInRange(int min, int max) {
        Random r = new Random();
        return r.ints(min, (max + 1)).limit(1).findFirst().getAsInt();
    }


    /**
     * @param min
     * @param max
     * @return Random number string
     */
    public static String getRandomStringInRange(String prefix, int min, int max) {
        StringBuffer stringBuffer = new StringBuffer();
        String parse = DateUtil.formatDate(new Date(), "yyyyMMddHHmmssSSS");
        Random r = new Random();
        String orderNo = stringBuffer.append(prefix).append(parse).append(String.valueOf(r.ints(min, (max + 1)).limit(1).findFirst().getAsInt())).toString();
        return orderNo;
    }

}
